#include <Interpreter.h>
#include <length.h>
#define STRFUNC(funcName)		strType##_##funcName

typedef _ptlong _str;
#define strType					_str 

#define NUM(x)                                  ((_ptlong)(x))

static constexpr _ptlong LOWB(x) {return ((~0) >> (sizeof(_ptlong) * 8 - x));}
static constexpr _ptlong HIGHB(x) {return ((~0) << (sizeof(_ptlong) * 8 -x));}


static slnode* CheckPermissionOfStream(strType tstr,_tcb* thr)
{
	slnode* pointer = thr->streams;
	while(pointer != NULL)
	{
		if((((u32)(tstr)) & HIGHB(24)) == (((u32)(pointer->mark)) & HIGHB(24)))
			return pointer;
		
	}
	return NULL;
}

static inline unsigned int ___StrChgPermission(strType orgStream, strType stream)
{
	slnode* pointer = CheckPermissionOfStream(orgStream,NOWT);
	pointer->mark = stream;
}

static inline unsigned int ___StrDelPermission(strType stream)
{
	slnode* pointer = CheckPermissionOfStream(orgStream,NOWT);
	RemoveSListNode(NOWT->streams,pointer);
}

#include "stream_model/model_Stream_IO.h"
#include "stream_model/model_vStream.c"

#define __StrChkPermission(stream)			CheckPermissionOfStream(stream,NOWT)
#define __StrChgPermission(originStream,stream)		___StrChgPermission(strType orgStream, strType stream)
#define __StrDelPermission(stream)			___StrDelPermission(strType stream)
#define __GetNextBlk(stream)                           JUMPING_TO(stream)
#define __SetNextBlk(stream,aftstream)                 SET_STREAM_JUMPING_TO(stream,aftstream)
#define __BlkStateAddr(stream)				GetVStreamStatAddr(stream)
#define __BlkWrittenAmount(stream)                      WRITTEN_AMOUNT(stream)
#define __BlkOpAddr(stream)				stream
#define __BlkAddOpAddr(stream,num)                      ((stream  + num) | HIGHB(sizeof(_ptlong) * 8 - PAGE_SIZE_OFFSET)) 



inline _ptlong STRFUNC(ConvertToPub)(strType stream)
{
  return stream;
}

inline _ptlong STRFUNC(ConvertToPrv)(strType stream)
{
  return stream;
}



#include "stream_model/model_Stream_IO.c"
